#!/usr/bin/python3

from json import loads
import sys
import os
from jsonschema import validate, ValidationError


class Verifier(object):
    def __init__(self, json, schema_dir):
        self.json = loads(json)['items']
        self.dir = schema_dir

    def schema(self, kind):
        p = os.path.join(self.dir, kind.lower() + '.json')
        with open(p, 'rt') as f:
            return loads(f.read())

    def verify(self):
        for item in self.json:
            print("Kind: %s" % item['kind'])
            try:
                validate(item, self.schema(item['kind']))
            except ValidationError as e:
                print(e.message)


def main():
    with open(sys.argv[1], 'rt') as f:
        _json = f.read()
        v = Verifier(_json, sys.argv[2])
        v.verify()


if __name__ == '__main__':
    main()
